package stdlib.nio

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.io.path.name
import kotlin.streams.toList

fun testFilesFind() {
    Files.find(Paths.get("."), 1, { path, attr ->
        println("-> ${path.toAbsolutePath()} ${path.name.endsWith("kt")}")
        attr.isRegularFile
    }).use { it ->
        it.forEach {
            println("${it.fileName},$it")
        }
    }
}

fun testFilterFilesFind(filename: String? = null): List<Path> {
    return Files.find(Paths.get("."), 1, { path, _ ->
        if (filename != null) {
            return@find filename == path.name
        }
        true
    }).toList()
}

fun main() {
    testFilesFind()
    println("${testFilterFilesFind().size}")
    println("${testFilterFilesFind("app0.apk").size}")
}